﻿using System.Configuration;
using System.Linq;
using Wedn.Net.Common;

namespace Wedn.Net.TEngine.Configuration
{
    /// <summary>
    /// 单项集合
    /// </summary>
    public class ViewEngineItemColletion : ConfigurationElementCollection
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public ViewEngineItemColletion()
        {
            AddElementName = "item";
        }
        /// <summary>
        /// 索引器
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public ViewEngineItem this[int index]
        {
            get { return BaseGet(index) as ViewEngineItem; }

            set
            {
                if (BaseGet(index) != null) BaseRemoveAt(index);
                BaseAdd(index, value);
            }
        }
        /// <summary>
        /// 创建新元素
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new ViewEngineItem();
        }
        /// <summary>
        /// 获取键
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ViewEngineItem)element).Value;
        }
        /// <summary>
        /// 转换成字符串数组
        /// </summary>
        /// <returns></returns>
        public string[] ToArray()
        {
            return (from ViewEngineItem item in this select item.Value.Replace("{theme_root}", Config.ThemeRoot).Replace("{theme_name}", Setting.Theme)).ToArray();
        }
    }
}